package resource

import (
	"context"
	"mallgo/internal/common/response"
	"mallgo/internal/resources/product/model"
	"mallgo/internal/resources/product/repository"
)

type ProductResource struct {
	productRepository *repository.ProductRepository
}

func NewProductResource(db *repository.ProductRepository) *ProductResource {
	return &ProductResource{db}
}

func (r *ProductResource) Create(ctx context.Context, product *model.Product) *response.ResponseObject {
	err := r.productRepository.Create(ctx, product)
	if err != nil {
		return response.Error(501, "创建失败")
	}
	return response.Success(product)
}
